package com.hjxr.quota.define.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.hjxr.common.core.controller.BaseController;
import com.hjxr.quota.define.domain.QuotaFormula;
import com.hjxr.quota.define.dto.QuotaCreateDto;
import com.hjxr.quota.define.service.IQuotaFormulaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 预指标公式存储表 前端控制器
 * </p>
 *
 * @author ma
 * @since 2020-10-20
 */
@RestController
@RequestMapping("/quotaFormula")
@Api(tags = "指标公式接口")
public class QuotaFormulaController extends BaseController {

    @Autowired
    private IQuotaFormulaService quotaFormulaService;

    @PostMapping("/insert")
    @ApiOperation(value = "存储指标公式")
    private R<Boolean> insert(@RequestBody List<QuotaFormula> quotaFormulaList ){
       return success(quotaFormulaService.saveBatch(quotaFormulaList));
    }

    @PostMapping("/create")
    @ApiOperation("指标生成指标")
    private R<Boolean> create(@RequestBody QuotaCreateDto quotaCreateDto ){
        return success(quotaFormulaService.createQuotaByQuota(quotaCreateDto));
    }

    /**
     * 此功能有疑问需要进一步确认！
     */
    @PostMapping("/createQuotaByType")
    @ApiOperation("根据所选生成值类型指标生成指标")
    private R<Boolean> createQuotaByType(@RequestBody QuotaCreateDto quotaCreateDto ){
        return success(quotaFormulaService.createQuotaByQuotaFromType(quotaCreateDto));
    }
    @GetMapping("/getString")
    @ApiOperation("获取字符串")
    private R<String> getString( ){
        String str="[ { \"name\": \"John\", \"city\": \"Seattle\" },\n{ \"name\": \"Mike\", \"city\": \"Los Angeles\" },\n { \"name\": \"Zach\", \"city\": \"New York\" }\n]";
        return success(str);
    }
}
